<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #canvas {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            border: 2px double #ff1c06;
        }
        #btn {
            position: fixed;
            left: 50%;
            top: 3%;
            transform: translate(-50%, 0);
            width: 100px;
            height: 50px;
        }
    </style>
</head>
<body>
<canvas id="canvas" width="600" height="600"></canvas>
<div id="btn">
    <button id="cls">清空</button>
    <button id="set">设置</button>
</div>
<script>
    /**
     * 出处：html5 canvas 开发详解
     * 索引：2.5
     */
    // 获取id
    function getId(id) {
        return document.getElementById(id);
    }
    var canvas = getId(canvas);
    var context = canvas.getContext();
    function colorSet(context, n) {
        for (var i = 0; i < n; i++) {

        }
        
    }
</script>
</body>
</html>